home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / CSMP Digests / csmp-v1-017.txt < prev    next >
Encoding:
Text File  |  1992-11-18  |  68.9 KB  |  1,652 lines  |  [TEXT/MPS ]

  1. C.S.M.P. Digest             Sun, 15 Mar 92       Volume 1 : Issue 17
  2.  
  3. Today's Topics:
  4.  
  5.     Given a file's vRefNum how do you get the complete path?
  6.     getting vRefNumber???
  7.     StandardPutFile
  8.  
  9.  
  10. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  11.  
  12. These digests are available (by using FTP, account anonymous, your email
  13. address as password) in the pub/mac/csmp-digest directory on ftp.cs.uoregon.
  14. edu (try skinner.cs.uoregon.edu if that doesn't work).  This is also the home
  15. of the comp.sys.mac.programmer Frequently Asked Questions list.
  16.  
  17. These digests are also available via email.  Just send a note saying that you
  18. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  19. automatically receive each new digest as it is created.
  20.  
  21. The articles in these digests are taken directly from comp.sys.mac.programmer.
  22. They are not edited; all articles included in this digest are in their original
  23. posted form.  The only articles that are -not- included in these digests are
  24. those which didn't receive any replies (except those that give information
  25. rather than ask a question).  All replies to each article are concatenated
  26. onto the original article in the order in which they were received.  Article
  27. threads are not added to the digests until the last article added to the
  28. thread is at least one month old (this is to ensure that the thread is dead
  29. before adding it to the digests).
  30.  
  31. Send administrative mail to mkelly@cs.uoregon.edu.
  32.  
  33. -------------------------------------------------------
  34.  
  35. From: david@oahu.cs.ucla.edu (David Dantowitz)
  36. Subject: Given a file's vRefNum how do you get the complete path?
  37. Date: 27 Jan 92 19:09:40 GMT
  38. Organization: UCLA Computer Science Department
  39.  
  40.  
  41. How does one get the full path for a file after selection with SFGetFile?
  42.  
  43. -- 
  44. David Dantowitz
  45. david@cs.ucla.edu
  46.  
  47. Singing Barbershop when I'm not computing...
  48.  
  49.  
  50.  
  51. - -------------------------
  52.  
  53. From: kpmiller@uokmax.ecn.uoknor.edu (Kent P Miller)
  54. Subject:  Given a file's vRefNum how do you get the complete path?
  55. Organization: Engineering Computer Network, University of Oklahoma, Norman, OK
  56. Date: Tue, 28 Jan 1992 04:44:03 GMT
  57.  
  58. In article <1992Jan27.190940.24636@cs.ucla.edu> david@oahu.cs.ucla.edu (David Dantowitz) writes:
  59. >
  60. >How does one get the full path for a file after selection with SFGetFile?
  61. Here's the code I copied out of the UMPG (works everytime for me):
  62. (pass the fname part of the sfreply as the first parameter and the vrefnum
  63. of the sfreply as the second parameter)
  64.  
  65.   function GetFullPath (x: str255; y: integer): str255;
  66.    var
  67.     tempName, thePath, comppath: Str255;
  68.     vParams: CInfoPBRec;
  69.     theError: OSerr;
  70.     i: integer;
  71.   begin
  72.    thePath := '';
  73.    tempName := '';
  74.    with vParams do
  75.     begin
  76.      ioCompletion := nil;
  77.      ioNamePtr := @tempName;
  78.      ioVRefNum := y;
  79.      ioFDirIndex := -1;
  80.      ioDrDirID := 0;
  81.      repeat
  82.       theError := PBGetCatInfo(@vParams, FALSE);
  83.       if (theError = noErr) then
  84.        begin
  85.        ioDRDirID := ioDRParID;
  86.        thePath := concat(tempName, ':', thePath);
  87.        tempName := '';
  88.        end;
  89.      until (theError <> noErr);
  90.      tempName := concat(thePath, x);
  91.      GetFullPath := tempName;
  92.     end;
  93.   end;
  94.  
  95.  
  96. -- 
  97. - ---------------------
  98. Kent Miller
  99. KENT@aardvark.ucs.uoknor.edu
  100. Bitnet -> KENT@uokucsvx
  101.  
  102.  
  103.  
  104. - -------------------------
  105.  
  106. From: keith@Apple.COM (Keith Rollin)
  107. Subject:  Given a file's vRefNum how do you get the complete path?
  108. Date: 28 Jan 92 23:31:54 GMT
  109. Organization: Apple Computer Inc., Cupertino, CA
  110.  
  111. In article <1992Jan27.190940.24636@cs.ucla.edu> david@oahu.cs.ucla.edu (David Dantowitz) writes:
  112. >
  113. >How does one get the full path for a file after selection with SFGetFile?
  114.  
  115. One looks at DTS sample code #18, or Technote #238, both available on
  116. ftp.apple.com and from APDA, as well as many other ftp sites and
  117. BBS's.
  118.  
  119. Of course, one must make sure that one is doing this for the right
  120. reason.  The only reason I can think of to create a full pathname is
  121. for display purposes (like MPW does in its menus and window titles, or
  122. Standard File does in its popup menu). "UNIX port" is _NOT_ a good
  123. reason.
  124.  
  125. -- 
  126. - ----------------------------------------------------------------------------
  127. Keith Rollin           ---            <Taligent .signature under construction>
  128. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  129.  
  130.  
  131.  
  132. - -------------------------
  133.  
  134. From: keith@Apple.COM (Keith Rollin)
  135. Subject:  Given a file's vRefNum how do you get the complete path?
  136. Date: 28 Jan 92 23:31:54 GMT
  137. Organization: Apple Computer Inc., Cupertino, CA
  138.  
  139. In article <1992Jan27.190940.24636@cs.ucla.edu> david@oahu.cs.ucla.edu (David Dantowitz) writes:
  140. >
  141. >How does one get the full path for a file after selection with SFGetFile?
  142.  
  143. One looks at DTS sample code #18, or Technote #238, both available on
  144. ftp.apple.com and from APDA, as well as many other ftp sites and
  145. BBS's.
  146.  
  147. Of course, one must make sure that one is doing this for the right
  148. reason.  The only reason I can think of to create a full pathname is
  149. for display purposes (like MPW does in its menus and window titles, or
  150. Standard File does in its popup menu). "UNIX port" is _NOT_ a good
  151. reason.
  152.  
  153. -- 
  154. - ----------------------------------------------------------------------------
  155. Keith Rollin           ---            <Taligent .signature under construction>
  156. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  157.  
  158.  
  159.  
  160. ---------------------------
  161.  
  162. From: Wade Williams
  163. Subject: getting vRefNumber???
  164. Date: 27 Jan 92 20:43:50 GMT
  165. Organization: Auburn University
  166.  
  167. Can anyone tell me..given a volume's name, how can I obtain its reference
  168. number?
  169.  
  170. Would I have to obtain the names of all mounted volumes, then compare them?
  171.  
  172. Thanks.
  173.  
  174. Wade
  175.  
  176.  
  177.  
  178. - -------------------------
  179.  
  180. From: jcav@quads.uchicago.edu (JohnC)
  181. Subject:  getting vRefNumber???
  182. Date: 28 Jan 92 00:27:14 GMT
  183. Organization: The Royal Society for Putting Things on Top of Other Things
  184.  
  185. In article <1992Jan27.154351.1661@ducvax.auburn.edu> Wade Williams writes:
  186. >Can anyone tell me..given a volume's name, how can I obtain its reference
  187. >number?
  188.  
  189. Here's the code I use:
  190.  
  191.  CONST
  192.   SYNC=false;
  193.   invalidVRefNum = $8000;
  194.  
  195.  TYPE
  196.   Str31=STRING[31]; {for HFS file/directory names}
  197.  
  198.  
  199.  FUNCTION VRefFromName (vName: Str31; VAR vRef: integer): OSErr;
  200.   VAR
  201.    pb: ParamBlockRec;
  202.  BEGIN
  203.   vName := concat(vName, ':');  {crucial -- will fail if volume is not HFS}
  204.   pb.ioNamePtr := @vName;
  205.   pb.ioVRefNum := invalidVRefNum; {ensures OS will _only_ use the name}
  206.   pb.ioVolIndex := -1; {ensures OS will use name at all}
  207.   VRefFromName := PBGetVInfo(@pb, SYNC);
  208.   vRef := pb.ioVRefNum;
  209.  END; { FUNCTION VRefFromName }
  210.  
  211.  FUNCTION VNameFromRef (vRef: integer; VAR vName: Str31): OSErr;
  212.   VAR
  213.    pb: ParamBlockRec;
  214.  BEGIN
  215.   vName := '';
  216.   pb.ioNamePtr := @vName;
  217.   pb.ioVRefNum := vRef;
  218.   pb.ioVolIndex := 0; {ensures OS will _only_ use vRef}
  219.   VNameFromRef := PBGetVInfo(@pb, SYNC);
  220.  END; { FUNCTION VNameFromRef }
  221.  
  222.  
  223.  
  224. - -------------------------
  225.  
  226. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  227. Subject:  getting vRefNumber???
  228. Date: 28 Jan 92 02:03:14 GMT
  229. Organization: NCRPDA, Curtin University
  230.  
  231. In article <1992Jan27.154351.1661@ducvax.auburn.edu>, Wade Williams writes:
  232. > Can anyone tell me..given a volume's name, how can I obtain its reference
  233. > number?
  234.  
  235. I would have replied by mail, but your From address was non-existant.
  236.  
  237. Anyway, you use PBGetVInfo, and the trick is (there is always a secret
  238. trick when dealing with the file manager :-) to make sure the volume
  239. name you give it has a colon at the end of it:
  240.  
  241. function GetVolInfo (var name: str63; var vrn: integer; index: integer; var CrDate: longInt): OSErr;
  242.   var
  243.   pb: paramBlockRec;
  244.   oe: OSErr;
  245. begin
  246.   with pb do begin
  247.   if (name <> '') & (name[length(name)] <> ':') then
  248.     name := concat(name, ':'); { The volume name must end in a colon }
  249.   pb.ioNamePtr := @name;
  250.   ioVRefNum := vrn;
  251.   ioVolIndex := index;
  252.   oe := PBGetVInfo(@pb, false);
  253.   if oe = noErr then begin
  254.     vrn := ioVRefNum;
  255.     CrDate := ioVCrDate;
  256.   end;
  257.   GetVolInfo := oe;
  258. end;
  259.  
  260. HTH,
  261.    Peter.
  262.  
  263. ______________________________________________________________________
  264. Peter N Lewis, NCRPDA, Curtin University      peter@cujo.curtin.edu.au
  265. GPO Box U1987, Perth WA 6001, AUSTRALIA            FAX: +61 9 367 8141
  266.  
  267.  
  268.  
  269. - -------------------------
  270.  
  271. From: kpmiller@uokmax.ecn.uoknor.edu (Kent P Miller)
  272. Subject:  getting vRefNumber???
  273. Date: 28 Jan 92 04:56:26 GMT
  274. Organization: Engineering Computer Network, University of Oklahoma, Norman, OK
  275.  
  276. >Can anyone tell me..given a volume's name, how can I obtain its reference
  277. >number?
  278. >
  279. The variable pb would be a parmBlkPtr.  
  280.  
  281.   pb := parmblkptr(newptr(sizeof(ParamBlockRec)));
  282.   pb^.ioNamePtr := @volname;
  283.   pb^.ioVRefNum := 0;
  284.   pb^.ioVolIndex := -1;
  285.   theerr := PBGetVInfo(pb, false);
  286. pb^.ioVrefNum will contain the vrefnum of the volume name specified in
  287. volname.
  288.  
  289. Kent Miller
  290.  
  291. -- 
  292. - ---------------------
  293. Kent Miller
  294. KENT@aardvark.ucs.uoknor.edu
  295. Bitnet -> KENT@uokucsvx
  296.  
  297.  
  298.  
  299. - -------------------------
  300.  
  301. From: keith@Apple.COM (Keith Rollin)
  302. Subject:  getting vRefNumber???
  303. Date: 28 Jan 92 23:45:09 GMT
  304. Organization: Apple Computer Inc., Cupertino, CA
  305.  
  306. In article <1992Jan28.020314.29642@cujo.curtin.edu.au> peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  307. >In article <1992Jan27.154351.1661@ducvax.auburn.edu>, Wade Williams writes:
  308. >> 
  309. >> Can anyone tell me..given a volume's name, how can I obtain its reference
  310. >> number?
  311. >
  312. >I would have replied by mail, but your From address was non-existant.
  313. >
  314. >Anyway, you use PBGetVInfo, and the trick is (there is always a secret
  315. >trick when dealing with the file manager :-) to make sure the volume
  316. >name you give it has a colon at the end of it:
  317.  
  318.     [ sample code removed ]
  319.  
  320. Depending on your needs, you may want to take a different approach from
  321. that shown in the sample code I removed. For instance, of you want to
  322. save a reference to a specific volume in a preferences file, you should
  323. save the volume's name and creation date. This allows you to
  324. differentiate between different volumes with the same name (this
  325. happens a lot if you have a bunch of floppies, all with the name
  326. 'Untitled'). To find the matching volume, I walk the list of mounted
  327. volumes, comparing names and creation dates:
  328.  
  329.     index = 0;
  330.     pb.volumeParam.ioNamePtr = volName;
  331.     do {
  332.         pb.volumeParam.ioVolIndex = ++index;
  333.         err = PBGetVInfoSync(&pb);
  334.         if (err == noErr) {
  335.             if ((**entry).creationDate == pb.volumeParam.ioVCrDate
  336.               && !PLstrcompare((StringPtr)volName, (StringPtr)(**entry).name)) {
  337.                 (**entry).vRefNum = pb.volumeParam.ioVRefNum;
  338.                 break;
  339.             }
  340.         }
  341.     } while (err == noErr);
  342.  
  343. Here, "entry" is a handle to a struct that contains the creation date and
  344. name of the volume I'm interested in. It also has a vRefNum field that
  345. gets filled in by the above procedure.
  346.  
  347. (How many people here are happy that "entry" is no longer a reserved C
  348. word? Raise your mice!)
  349.  
  350. -- 
  351. - ----------------------------------------------------------------------------
  352. Keith Rollin           ---            <Taligent .signature under construction>
  353. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  354.  
  355.  
  356.  
  357. - -------------------------
  358.  
  359. From: keith@Apple.COM (Keith Rollin)
  360. Subject:  getting vRefNumber???
  361. Date: 28 Jan 92 23:45:09 GMT
  362. Organization: Apple Computer Inc., Cupertino, CA
  363.  
  364. In article <1992Jan28.020314.29642@cujo.curtin.edu.au> peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  365. >In article <1992Jan27.154351.1661@ducvax.auburn.edu>, Wade Williams writes:
  366. >> 
  367. >> Can anyone tell me..given a volume's name, how can I obtain its reference
  368. >> number?
  369. >
  370. >I would have replied by mail, but your From address was non-existant.
  371. >
  372. >Anyway, you use PBGetVInfo, and the trick is (there is always a secret
  373. >trick when dealing with the file manager :-) to make sure the volume
  374. >name you give it has a colon at the end of it:
  375.  
  376.     [ sample code removed ]
  377.  
  378. Depending on your needs, you may want to take a different approach from
  379. that shown in the sample code I removed. For instance, of you want to
  380. save a reference to a specific volume in a preferences file, you should
  381. save the volume's name and creation date. This allows you to
  382. differentiate between different volumes with the same name (this
  383. happens a lot if you have a bunch of floppies, all with the name
  384. 'Untitled'). To find the matching volume, I walk the list of mounted
  385. volumes, comparing names and creation dates:
  386.  
  387.     index = 0;
  388.     pb.volumeParam.ioNamePtr = volName;
  389.     do {
  390.         pb.volumeParam.ioVolIndex = ++index;
  391.         err = PBGetVInfoSync(&pb);
  392.         if (err == noErr) {
  393.             if ((**entry).creationDate == pb.volumeParam.ioVCrDate
  394.               && !PLstrcompare((StringPtr)volName, (StringPtr)(**entry).name)) {
  395.                 (**entry).vRefNum = pb.volumeParam.ioVRefNum;
  396.                 break;
  397.             }
  398.         }
  399.     } while (err == noErr);
  400.  
  401. Here, "entry" is a handle to a struct that contains the creation date and
  402. name of the volume I'm interested in. It also has a vRefNum field that
  403. gets filled in by the above procedure.
  404.  
  405. (How many people here are happy that "entry" is no longer a reserved C
  406. word? Raise your mice!)
  407.  
  408. -- 
  409. - ----------------------------------------------------------------------------
  410. Keith Rollin           ---            <Taligent .signature under construction>
  411. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  412.  
  413.  
  414.  
  415. ---------------------------
  416.  
  417. From: gtall@ogre.cica.indiana.edu (Gerry Allwein)
  418. Subject: StandardPutFile
  419. Organization: Center for Innovative Computing Applications (CICA), Indiana University
  420. Date:  7 Feb 92 15:41:10 GMT
  421.  
  422. I've been attempting to StandardPutFile and find that it the vRefNum field
  423. of the sfFile for the reply is always set to -1, not at all what the old
  424. SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  425. know how to fix this? Is it a bug in StandardPutFile?
  426.  
  427. Gerry
  428.  
  429.  
  430.  
  431.  
  432. - -------------------------
  433.  
  434. From: johnsd2@vccsouth28.its.rpi.edu (Daniel Norman Johnson)
  435. Subject:  StandardPutFile
  436. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  437. Date: Sat, 8 Feb 1992 03:32:39 GMT
  438.  
  439. > I've been attempting to StandardPutFile and find that it the vRefNum field
  440. > of the sfFile for the reply is always set to -1, not at all what the old
  441. > SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  442. > know how to fix this? Is it a bug in StandardPutFile?
  443.  
  444. > Gerry
  445.  
  446. Yes, I just had to figure that out. Its really supposed to do that.
  447.  
  448. The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  449. a volume reference number, *NOT* a working directory reference number.
  450. (read Inside Macintosh Volume 4 for what a Working Directory is, if you
  451. do not know)
  452.  
  453. I know, they are always called vRefNums. Usually they do not mean it. What
  454. you need to do is use the OpenWD (open working directory) command System 7.0
  455. provides to make that into a Working Directory Refnum; Do not worry about
  456. the fact that this command is not availiable in system 6.0, because FileSpecs
  457. and such things don't even happen. So just use OpenWD and don't use PBOpenWD (
  458. or whatever the low-level equivalent is);
  459.  
  460. You'll need to use the parent directory id for this also.
  461.  
  462. For that other parameter (PBprocID or something like that?) just pass 0;
  463. that way if you need to access the same working directory more than once it'll
  464. just give you the same Working Directory. I don't know if you are supposed
  465. to close the WD, does anybody here?
  466.  
  467. This is necessary if you ever have to access a file which is given by
  468. a file-spec with old routines. However, if you are using the new FileSpec
  469. routines, you can just pass the FileSpec to them. If you are writing
  470. System-7 dependant stuff, I recommend this because you do not have to deal
  471. with the Poor Man's Search Path. But that doesn't make a difference with
  472. StandardPutFile/GetFile.
  473.  
  474.  
  475.  
  476. - -------------------------
  477.  
  478. From: jcav@quads.uchicago.edu (JohnC)
  479. Subject: about working directories (was Re: StandardPutFile)
  480. Date: 8 Feb 92 20:07:12 GMT
  481. Organization: The Royal Society for Putting Things on Top of Other Things
  482.  
  483. In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  484. >The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  485. >a volume reference number, *NOT* a working directory reference number.
  486. >(read Inside Macintosh Volume 4 for what a Working Directory is, if you
  487. >do not know)
  488. >
  489. >I know, they are always called vRefNums. Usually they do not mean it. What
  490. >you need to do is use the OpenWD (open working directory) command System 7.0
  491. >provides to make that into a Working Directory Refnum; Do not worry about
  492. >the fact that this command is not availiable in system 6.0, because FileSpecs
  493. >and such things don't even happen. So just use OpenWD and don't use PBOpenWD (
  494. >or whatever the low-level equivalent is);
  495.  
  496. The old Standard File routines return a real vRefNum if the chosen file is
  497. in the root directory, else they return a wdRefNum that specifies the directory
  498. that contains the file.  _OpenWD (and all the other high-level HFS calls)
  499. _are_ available under system 6, since they are all implemented by glue code
  500. in libraries.  The _only_ working directory call that you should _ever_
  501. make is _GetWDInfo (or _PBGetWDInfo, of course).
  502.  
  503. >You'll need to use the parent directory id for this also.
  504. >
  505. >For that other parameter (PBprocID or something like that?) just pass 0;
  506. >that way if you need to access the same working directory more than once it'll
  507. >just give you the same Working Directory. I don't know if you are supposed
  508. >to close the WD, does anybody here?
  509.  
  510. NoNoNoNo.  Working directories are a compatibility hack for applications
  511. that don't know about HFS and directory IDs.  You never have to make your
  512. own.  When using the old Standard File routines, simply pass the contents
  513. of the vRefNum field in the reply record to _GetWDInfo.  This routine will
  514. return the corresponding _real_ volume refNum and a directoryID.  Once you
  515. have these, you need not consider the wdRefNum any longer.  If you are using
  516. the new Standard File routines, just use the fileSpec, or its component parts.
  517.  
  518. >This is necessary if you ever have to access a file which is given by
  519. >a file-spec with old routines. However, if you are using the new FileSpec
  520. >routines, you can just pass the FileSpec to them. If you are writing
  521. >System-7 dependant stuff, I recommend this because you do not have to deal
  522. >with the Poor Man's Search Path. But that doesn't make a difference with
  523. >StandardPutFile/GetFile.
  524.  
  525. You _NEVER_ _EVER_ have to build a working directory.*  If you need to use
  526. the information from a fileSpec when the fileSpec-based File manager calls
  527. are not available, simply pass the component parts (vRefnum, directoryID,
  528. name) to routines like _HOpen, _HCreate, _HCreateResFile, etc.
  529.  
  530.  
  531.  
  532. * -- Actually, you do if you're going to launch an application yourself
  533. under a pre-System 7 OS.  But that's pretty rare, and is the _ONLY_
  534. exception.
  535.  
  536. -- 
  537. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  538. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  539. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  540. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  541.  
  542.  
  543.  
  544. - -------------------------
  545.  
  546. From: keith@Apple.COM (Keith Rollin)
  547. Subject:  StandardPutFile
  548. Date: 9 Feb 92 01:17:22 GMT
  549. Organization: Apple Computer Inc., Cupertino, CA
  550.  
  551. In article <gtall.697477270@ogre> gtall@ogre.cica.indiana.edu (Gerry Allwein) writes:
  552. >I've been attempting to StandardPutFile and find that it the vRefNum field
  553. >of the sfFile for the reply is always set to -1, not at all what the old
  554. >SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  555. >know how to fix this? Is it a bug in StandardPutFile?
  556.  
  557. There's nothing to fix, and there is no bug. If you'd just used the
  558. value returned to you instead of trying to interpret it, you'd probably
  559. have found that it worked just fine.
  560.  
  561. You're probably confused because for the first time in your life,
  562. Standard File is actually returning a vRefNum in the vRefNum field.
  563. Previous versions of Standard File were forced to return a working
  564. directory ID because there was no other way to return a DirID. Now that
  565. there is a DirID field in the new Standard File calls, there is no
  566. reason to return a working directory ID. -1 is the vRefNum for the boot
  567. volume, and is a perfectly fine value. (If you have Macsbug, drop into
  568. it and execute the "vol" dcmd to see what I mean.) I'll bet that if
  569. you'd tried to use it, it would have worked like a champ. Unless, of
  570. course, you are getting -1 when selecting other volumes, in which
  571. "something odd is happening."
  572.  
  573. Try using SFPPutFile to create a file at the root level of your boot
  574. volume. You should receive a -1 as the vRefNum there, too.
  575.  
  576. Please refer to the File Manager chapter of IM IV for a description
  577. of working directory numbers, and the Standard File chapters of IM's
  578. I, IV, and VI for a description of what Standard File returns.
  579.  
  580. -- 
  581. - ----------------------------------------------------------------------------
  582. Keith Rollin           ---            <Taligent .signature under construction>
  583. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  584.  
  585.  
  586.  
  587. - -------------------------
  588.  
  589. From: johnsd2@vccsouth20.its.rpi.edu (Daniel Norman Johnson)
  590. Subject:  about working directories (was Re: StandardPutFile)
  591. Date: 9 Feb 92 02:33:14 GMT
  592. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  593.  
  594. In article <1992Feb8.200712.10768@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  595. |> In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  596. |> >The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  597. |> >a volume reference number, *NOT* a working directory reference number.
  598.  
  599.     [ and so on until... ]
  600.  
  601. |> NoNoNoNo.  Working directories are a compatibility hack for applications
  602. |> that don't know about HFS and directory IDs.  You never have to make your
  603. |> own.  When using the old Standard File routines, simply pass the contents
  604. |> of the vRefNum field in the reply record to _GetWDInfo.  This routine will
  605. |> return the corresponding _real_ volume refNum and a directoryID.  Once you
  606. |> have these, you need not consider the wdRefNum any longer.  If you are using
  607. |> the new Standard File routines, just use the fileSpec, or its component parts.
  608.  
  609.     [ and there's more, but this is what I wanted to comment on ]
  610.  
  611. I assure you, this particular hack is not going anywhere. If apple removes
  612. it, every application that uses SFGetFile will break. It does mean
  613. using 1 less variable, however, and I don't see any reason why the system
  614. can't keep track of something for me.
  615.  
  616. The only reason I can think of for not using them is that it is possible that
  617. Apple will change the format of the File Spec record (I doubt it myself),
  618. and if that happens only using the real FSp-whatever routines will save you.
  619.  
  620. Of course, this is just a matter of personal taste. If you like directory
  621. IDs, use 'em. But this JohnC whose message Im responding to make Working
  622. Directories sound so very Evil that I thot I should say something.
  623.  
  624. On the other hand, I must admit I had (blush) forgotten about those H-whatever
  625. routines, as I do not use them very often. The technique John tells of would work
  626. too, you don't have to use Working Diretories (as I thot you did).
  627.  
  628.                 - an embarrased Mac Programmer
  629.  
  630.  
  631.  
  632. - -------------------------
  633.  
  634. From: gtall@ogre.cica.indiana.edu (Gerry Allwein)
  635. Subject:  StandardPutFile
  636. Date: 9 Feb 92 14:19:34 GMT
  637. Organization: Center for Innovative Computing Applications (CICA), Indiana University
  638.  
  639. In <62596@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
  640.  
  641. >In article <gtall.697477270@ogre> gtall@ogre.cica.indiana.edu (Gerry Allwein) writes:
  642. >>I've been attempting to StandardPutFile and find that it the vRefNum field
  643. >>of the sfFile for the reply is always set to -1, not at all what the old
  644. >>SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  645. >>know how to fix this? Is it a bug in StandardPutFile?
  646.  
  647. >There's nothing to fix, and there is no bug. If you'd just used the
  648. >value returned to you instead of trying to interpret it, you'd probably
  649. >have found that it worked just fine.
  650.  
  651. >You're probably confused because for the first time in your life,
  652. >Standard File is actually returning a vRefNum in the vRefNum field.
  653. >Previous versions of Standard File were forced to return a working
  654. >directory ID because there was no other way to return a DirID. Now that
  655. >there is a DirID field in the new Standard File calls, there is no
  656. >reason to return a working directory ID. -1 is the vRefNum for the boot
  657. >volume, and is a perfectly fine value. (If you have Macsbug, drop into
  658. >it and execute the "vol" dcmd to see what I mean.) I'll bet that if
  659. >you'd tried to use it, it would have worked like a champ. Unless, of
  660. >course, you are getting -1 when selecting other volumes, in which
  661. >"something odd is happening."
  662.  
  663. >Try using SFPPutFile to create a file at the root level of your boot
  664. >volume. You should receive a -1 as the vRefNum there, too.
  665.  
  666. >Please refer to the File Manager chapter of IM IV for a description
  667. >of working directory numbers, and the Standard File chapters of IM's
  668. >I, IV, and VI for a description of what Standard File returns.
  669.  
  670. That would be, "for the first time in your (Keith Rollin's) life", thank you!
  671.  
  672. Yes, I found the problem. Unfortunately for you, MacApp 2.0.1 and MacApp2.0
  673. rely on working directories. I know, that is how I found the problem. And this
  674. is a BUG because it isn't documented that there is variance with respect to
  675. the documentation IM1,4,6. I call that bug, you can call it anything you like.
  676.  
  677. Gerry
  678.  
  679.  
  680.  
  681. - -------------------------
  682.  
  683. From: johnsd2@jec306.its.rpi.edu (Daniel Norman Johnson)
  684. Subject:  StandardPutFile
  685. Date: 9 Feb 92 15:44:30 GMT
  686. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  687.  
  688. In article <gtall.697645174@ogre>, gtall@ogre.cica.indiana.edu (Gerry Allwein) writes:
  689. |> In <62596@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
  690. |> 
  691. |> >In article <gtall.697477270@ogre> gtall@ogre.cica.indiana.edu (Gerry Allwein) writes:
  692. |> >>I've been attempting to StandardPutFile and find that it the vRefNum field
  693. |> >>of the sfFile for the reply is always set to -1, not at all what the old
  694. |> >>SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  695. |> >>know how to fix this? Is it a bug in StandardPutFile?
  696. |> 
  697. |> >There's nothing to fix, and there is no bug. If you'd just used the
  698. |> >value returned to you instead of trying to interpret it, you'd probably
  699. |> >have found that it worked just fine.
  700. |> 
  701. |> >You're probably confused because for the first time in your life,
  702. |> >Standard File is actually returning a vRefNum in the vRefNum field.
  703. |> >Previous versions of Standard File were forced to return a working
  704. |> >directory ID because there was no other way to return a DirID. Now that
  705. |> >there is a DirID field in the new Standard File calls, there is no
  706. |> >reason to return a working directory ID. -1 is the vRefNum for the boot
  707. |> >volume, and is a perfectly fine value. (If you have Macsbug, drop into
  708. |> >it and execute the "vol" dcmd to see what I mean.) I'll bet that if
  709. |> >you'd tried to use it, it would have worked like a champ. Unless, of
  710. |> >course, you are getting -1 when selecting other volumes, in which
  711. |> >"something odd is happening."
  712. |> 
  713. |> >Try using SFPPutFile to create a file at the root level of your boot
  714. |> >volume. You should receive a -1 as the vRefNum there, too.
  715. |> 
  716. |> >Please refer to the File Manager chapter of IM IV for a description
  717. |> >of working directory numbers, and the Standard File chapters of IM's
  718. |> >I, IV, and VI for a description of what Standard File returns.
  719. |> 
  720. |> That would be, "for the first time in your (Keith Rollin's) life", thank you!
  721. |> 
  722. |> Yes, I found the problem. Unfortunately for you, MacApp 2.0.1 and MacApp2.0
  723. |> rely on working directories. I know, that is how I found the problem. And this
  724. |> is a BUG because it isn't documented that there is variance with respect to
  725. |> the documentation IM1,4,6. I call that bug, you can call it anything you like.
  726. |> 
  727. |> Gerry
  728.  
  729. Actually, it isn't a bug. What you are officialy supposed to do is pass
  730. the sfFile (an FSSpec) to one of the FSp* routines, and that works just dandy.
  731.  
  732. I do think Apple should have document the difference, but it was really supposed
  733. to be there.
  734.  
  735. What --->is<--- is bug is what happens if you follow my instructions however.
  736. I said that OpenWD() should be called with a PBProcID field of 0, and this
  737. is WRONG. I thot PBProcID was for your applications use, but it isn't. Its
  738. the way the system knows who owns any particular Working Directory. Pass
  739. your applications signature.
  740.  
  741. Passing 0 works, but it means that you would be SHARING Working directories
  742. with any other app that also passes 0, which is bad. But then, that's
  743. what you get for listening to me. :)
  744.  
  745. Well, I'll just crawl off into a corner in hide now, as I've spread as much
  746. misinformation as I can for 1 weekend...
  747.  
  748.  
  749.  
  750. - -------------------------
  751.  
  752. From: jcav@quads.uchicago.edu (JohnC)
  753. Subject:  about working directories (was Re: StandardPutFile)
  754. Date: 9 Feb 92 18:45:45 GMT
  755. Organization: The Royal Society for Putting Things on Top of Other Things
  756.  
  757. In article <_=ds!d-@rpi.edu> johnsd2@rpi.edu writes:
  758. >I assure you, this particular hack is not going anywhere. If apple removes
  759. >it, every application that uses SFGetFile will break. It does mean
  760. >using 1 less variable, however, and I don't see any reason why the system
  761. >can't keep track of something for me.
  762.  
  763. Ah, but it is, via the directory ID.  If you don't like piles of variables,
  764. just use fileSpecs all the time (one variable) and fill in their fields
  765. yourself if System 7 is not available.
  766.  
  767. >The only reason I can think of for not using them is that it is possible that
  768. >Apple will change the format of the File Spec record (I doubt it myself),
  769. >and if that happens only using the real FSp-whatever routines will save you.
  770. >
  771. >Of course, this is just a matter of personal taste. If you like directory
  772. >IDs, use 'em. But this JohnC whose message Im responding to make Working
  773. >Directories sound so very Evil that I thot I should say something.
  774.  
  775. Hey, "evil" is most certainly an exaggeration. ;-)  I agree that working
  776. directories aren't going away soon, if ever, but I maintain that they should
  777. never be used by code that wasn't written by Apple Blue Meanies.  One major
  778. disadvantage is that there is a fixed maximum number of working directories
  779. for all applications on the machine, and thought I'm sure the system tries
  780. to be clever at deallocating them as soon as they are no longer needed, one
  781. could run out if one opens many files from different folders.  Another problem
  782. is that as long as a working directory exists for a folder, when you try to
  783. throw away that folder, the Finder will complain that the item is "in use" or
  784. contains items that are "in use".  I'm sure this is very confusing for
  785. novices, and is the main reason I don't use working directories.
  786.  
  787.  
  788. -- 
  789. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  790. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  791. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  792. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  793.  
  794.  
  795.  
  796. - -------------------------
  797.  
  798. From: jcav@quads.uchicago.edu (JohnC)
  799. Subject:  StandardPutFile
  800. Date: 9 Feb 92 18:49:46 GMT
  801. Organization: The Royal Society for Putting Things on Top of Other Things
  802.  
  803. In article <6xds##d@rpi.edu> johnsd2@rpi.edu writes:
  804. >What --->is<--- is bug is what happens if you follow my instructions however.
  805. >I said that OpenWD() should be called with a PBProcID field of 0, and this
  806. >is WRONG. I thot PBProcID was for your applications use, but it isn't. Its
  807. >the way the system knows who owns any particular Working Directory. Pass
  808. >your applications signature.
  809. >
  810. >Passing 0 works, but it means that you would be SHARING Working directories
  811. >with any other app that also passes 0, which is bad. But then, that's
  812. >what you get for listening to me. :)
  813.  
  814. Actually, under Multifinder/Process Manager, the procID is ignored by the
  815. system.  Instead, it tags the working directory with a value uniquely
  816. identifying the process that created it, to facilitate automatic
  817. deallocation when the process terminates.
  818.  
  819. -- 
  820. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  821. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  822. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  823. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  824.  
  825.  
  826.  
  827. - -------------------------
  828.  
  829. From: ksand@apple.com (Kent Sandvik)
  830. Subject:  StandardPutFile
  831. Date: 10 Feb 92 05:00:23 GMT
  832. Organization: MacDTS Mongols
  833.  
  834. In article <gtall.697645174@ogre>, gtall@ogre.cica.indiana.edu (Gerry Allwein) writes:
  835. > Yes, I found the problem. Unfortunately for you, MacApp 2.0.1 and MacApp2.0
  836. > rely on working directories. I know, that is how I found the problem. And this
  837. > is a BUG because it isn't documented that there is variance with respect to
  838. > the documentation IM1,4,6. I call that bug, you can call it anything you like.
  839.  
  840. MacApp 3.0 tries to use FSSpecs if possible, see sample below:
  841.  
  842. pascal OSErr TFile::CreateRsrcFork()
  843. {
  844.     if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
  845.     {
  846.         FSSpec theFile = fFileSpec;
  847.     
  848.         FSpCreateResFile(theFile, fCreator, fFileType, fScriptTag);
  849.     }
  850.     else
  851.     {
  852.         CStr63 fileName = fFileSpec.name;
  853.         
  854.         HCreateResFile(fFileSpec.vRefNum, fFileSpec.parID, fileName);
  855.         
  856.         if (ResError() == noErr)
  857.         {
  858.             HParamBlockRec pb;
  859.             
  860.             GetFileInfo(pb);
  861.             pb.fileParam.ioFlFndrInfo.fdCreator = fCreator;
  862.             pb.fileParam.ioFlFndrInfo.fdType = fFileType;
  863.             SetFileInfo(pb);
  864.         }
  865.     }
  866.     return ResError();
  867. }
  868.  
  869. Kent Sandvik/DTS
  870.  
  871.  
  872.  
  873. - -------------------------
  874.  
  875. From: sagen@techbook.com (Milton Sagen)
  876. Subject:  StandardPutFile
  877. Date: 10 Feb 92 07:12:47 GMT
  878. Organization: TECHbooks of Beaverton Oregon - Public Access Unix
  879.  
  880. In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  881. >
  882. >I know, they are always called vRefNums. Usually they do not mean it. What
  883. >you need to do is use the OpenWD (open working directory) command System 7.0
  884. >provides to make that into a Working Directory Refnum; Do not worry about
  885.  
  886. Why?  The FSSpec record not only gives you the vRefNum but also the dirID of
  887. the parent directory so why not use those file manager calls which use a
  888. true vRefNum and dirID?
  889.  
  890. >the fact that this command is not availiable in system 6.0, because FileSpecs
  891. >and such things don't even happen. So just use OpenWD and don't use PBOpenWD (
  892.  
  893. Hasn't Apple been suggesting not to open working directories?  It seems to me
  894. one of the Tech Notes suggested against it.
  895.  
  896. >You'll need to use the parent directory id for this also.
  897. >
  898. >For that other parameter (PBprocID or something like that?) just pass 0;
  899. >that way if you need to access the same working directory more than once it'll
  900. >just give you the same Working Directory. I don't know if you are supposed
  901. >to close the WD, does anybody here?
  902.  
  903. If you don't have to open it then you don't have to worry about whether to
  904. close it or not.
  905. -- 
  906. Milton E. Sagen                          sagen@techbook.COM
  907. Software Engineer                        !{tektronix!nosun,uunet}techbook!sagen 
  908. Prometheus Products, Inc.                (503) 692-9600 (voice)
  909. Tualatin, OR 97062                       (503) 691-1101 (fax)
  910.  
  911.  
  912.  
  913. - -------------------------
  914.  
  915. From: russotto@eng.umd.edu (Matthew T. Russotto)
  916. Subject:  StandardPutFile
  917. Date: 10 Feb 92 15:21:47 GMT
  918. Organization: University of Maryland, College Park, College of Engineering
  919.  
  920. In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  921. >> I've been attempting to StandardPutFile and find that it the vRefNum field
  922. >> of the sfFile for the reply is always set to -1, not at all what the old
  923. >> SFPPutFile returns for the vRefNum. This is system 7.0, on a Mac ci. Anyone
  924. >> know how to fix this? Is it a bug in StandardPutFile?
  925. >
  926. >> Gerry
  927. >
  928. >Yes, I just had to figure that out. Its really supposed to do that.
  929. >
  930. >The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  931. >a volume reference number, *NOT* a working directory reference number.
  932. >(read Inside Macintosh Volume 4 for what a Working Directory is, if you
  933. >do not know)
  934. >
  935. >I know, they are always called vRefNums. Usually they do not mean it. What
  936. >you need to do is use the OpenWD (open working directory) command System 7.0
  937. ...
  938. >You'll need to use the parent directory id for this also.
  939. ...
  940. >This is necessary if you ever have to access a file which is given by
  941. >a file-spec with old routines. However, if you are using the new FileSpec
  942.  
  943. Huh?  No it isn't-- since the Mac Plus, the routines for accessing a file
  944. given the directory ID, real volume reference number, and partial
  945. pathname have existed-- i.e.
  946. PBHOpen
  947. PBHGetFInfo
  948. PBHDelete
  949. ....
  950. Newer development systems even have high-level glue for these routines.
  951. -- 
  952. Matthew T. Russotto    russotto@eng.umd.edu    russotto@wam.umd.edu
  953. Your superior intellect is no match for our puny weapons! -- The Simpsons
  954. Just say NO to police searches and seizures.  Make them use force.
  955. (not responsible for bodily harm resulting from following above advice)
  956.  
  957.  
  958.  
  959. - -------------------------
  960.  
  961. From: dorner@pequod.cso.uiuc.edu (Steve Dorner)
  962. Subject:  about working directories (was Re: StandardPutFile)
  963. Organization: University of Illinois at Urbana-Champaign
  964. Date: Mon, 10 Feb 1992 21:19:47 GMT
  965.  
  966. jcav@midway.uchicago.edu writes:
  967. >Hey, "evil" is most certainly an exaggeration. ;-)  I agree that working
  968. >directories aren't going away soon, if ever, but I maintain that they should
  969. >never be used by code that wasn't written by Apple Blue Meanies.
  970.  
  971. My $.02:
  972.  
  973. There's no harm in using Working directories that you get from standard file
  974. or the Finder; as people have said, these aren't going away soon.
  975. Furthermore the OS manages them, which takes away one of the big problems.
  976.  
  977. I think the real stricture lies in CREATING the darn things.  If your
  978. program is going to call OpenWD, think twice and three times.  It's
  979. really very unpleasant, because you'll never know when you can or can't
  980. get rid of them.  You'll either run out (someday), or you'll end up
  981. disposing one that standard file or somebody else was looking at, with
  982. bad consequences.
  983. -- 
  984. Steve Dorner, U of Illinois Computing Services Office
  985. (He who has done nothing for UIUC students, except harass them.)
  986. Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner
  987.  
  988.  
  989.  
  990. - -------------------------
  991.  
  992. From: ABSURD@applelink.apple.com (Tim Dierks, ToyMeister, Cray abuser)
  993. Subject:  about working directories (was Re: StandardPutFile)
  994. Date: 10 Feb 92 22:36:14 GMT
  995. Organization: MacDTS, Apple Computer
  996.  
  997. In article <_=ds!d-@rpi.edu>, johnsd2@vccsouth20.its.rpi.edu (Daniel Norman Johnson) writes:
  998. > In article <1992Feb8.200712.10768@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  999. > |> In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  1000. > |> >The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  1001. > |> >a volume reference number, *NOT* a working directory reference number.
  1002. >     [ and so on until... ]
  1003. > |> NoNoNoNo.  Working directories are a compatibility hack for applications
  1004. > |> that don't know about HFS and directory IDs.  You never have to make your
  1005. > |> own.  When using the old Standard File routines, simply pass the contents
  1006. > |> of the vRefNum field in the reply record to _GetWDInfo.  This routine will
  1007. > |> return the corresponding _real_ volume refNum and a directoryID.  Once you
  1008. > |> have these, you need not consider the wdRefNum any longer.  If you are using
  1009. > |> the new Standard File routines, just use the fileSpec, or its component parts.
  1010. >     [ and there's more, but this is what I wanted to comment on ]
  1011. > I assure you, this particular hack is not going anywhere. If apple removes
  1012. > it, every application that uses SFGetFile will break. It does mean
  1013. > using 1 less variable, however, and I don't see any reason why the system
  1014. > can't keep track of something for me.
  1015.  
  1016. In this case, there's a couple of good reasons not to have the System keeping
  1017. track of this for you.  First, the system doesn't have any way to tell what 
  1018. directory records you're using and which you're not.  If I open and close
  1019. 500 files in your application, should the system maintain 500 different
  1020. working directories for the locations of each of these files?  How can it
  1021. be sure that your program will never need to look at any of these files
  1022. again?  Obviously, it's going to need to deallocate some of the records at
  1023. some point.  If you go back and try to use that working directory again,
  1024. Bad Things will happen.  Secondly, you're abstracting yourself from the
  1025. actual structure of the file system and from the approved format for these
  1026. values.  This means that if you need to index into a sub-directory, you'll
  1027. actually have to create a working directory to get the single, 16-bit
  1028. number the rest of your code expects.  Furthermore, if you want to use
  1029. alias records, etc, you'll have to resolve the working directory to build
  1030. the FSSpec you need.  It seems like a lot of useless work to convert back
  1031. and forth, back and forth.  Why not just use an FSSpec?  It's also just
  1032. one variable, only it's a little bigger than a vRefNum + filename (which is
  1033. 2 variables!)
  1034.  
  1035. Support for working directories may not be forever.  It's hard to say at
  1036. this point, but you should avoid using working directories if at all
  1037. possible.
  1038.  
  1039. Tim Dierks
  1040. MacDTS, but I speak for myself
  1041.  
  1042.  
  1043.  
  1044. - -------------------------
  1045.  
  1046. From: neeri@iis.ethz.ch (Matthias Ulrich Neeracher)
  1047. Subject:  about working directories (was Re: StandardPutFile)
  1048. Date: 11 Feb 92 16:53:24 GMT
  1049. Organization: Integrated Systems Laboratory, ETH, Zurich
  1050.  
  1051. In article <20177@goofy.Apple.COM> ABSURD@applelink.apple.com (Tim Dierks, ToyMeister, Cray abuser) writes:
  1052. >In article <_=ds!d-@rpi.edu>, johnsd2@vccsouth20.its.rpi.edu (Daniel Norman Johnson) writes:
  1053. >In this case, there's a couple of good reasons not to have the System keeping
  1054. >track of this for you.  
  1055. >[Lots of good reasons not to use WDs deleted]
  1056. >Support for working directories may not be forever.  It's hard to say at
  1057. >this point, but you should avoid using working directories if at all
  1058. >possible.
  1059.  
  1060. The reason why I use working directories in some of my applications is that I
  1061. need ways to set the default directory, and HSetVol will break at the moment
  1062. someone else decides to call GetVol/SetVol. So, I see no alternative to using
  1063. working directories.
  1064.  
  1065. Matthias
  1066.  
  1067. - ---
  1068. Matthias Neeracher                                   neeri@iis.ethz.ch
  1069.   "... Rice walked out wondering if the world was nothing but wimps,
  1070.    pimps, psychos and sex fiends" -- James Ellroy, _Suicide Hill_
  1071.  
  1072.  
  1073.  
  1074. - -------------------------
  1075.  
  1076. From: johnsd2@rs6225.ecs.rpi.edu (Daniel Norman Johnson)
  1077. Subject:  about working directories (was Re: StandardPutFile)
  1078. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  1079. Date: Tue, 11 Feb 1992 19:47:42 GMT
  1080.  
  1081. In article <1992Feb9.184545.2809@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  1082. |> >  [ various things until ] . It does mean
  1083. |> >using 1 less variable, however, and I don't see any reason why the system
  1084. |> >can't keep track of something for me.
  1085. |> 
  1086. |> Ah, but it is, via the directory ID.  If you don't like piles of variables,
  1087. |> just use fileSpecs all the time (one variable) and fill in their fields
  1088. |> yourself if System 7 is not available.
  1089. |> 
  1090.  
  1091. So I can keep track of 3 fields instead of 2. Hmmmmm... Of course under system
  1092. 7 the system will take care of it for me, and I will (honest honest) use them
  1093. when I write Sys-7 dependant stuff. But I get to write the FSp routines if
  1094. it doesn't. Sounds like I get to keep track of 'em.
  1095.  
  1096. |> >The only reason I can think of for not using them is that it is possible that
  1097. |> >Apple will change the format of the File Spec record (I doubt it myself),
  1098. |> >and if that happens only using the real FSp-whatever routines will save you.
  1099. |> >
  1100. |> >Of course, this is just a matter of personal taste. If you like directory
  1101. |> >IDs, use 'em. But this JohnC whose message Im responding to make Working
  1102. |> >Directories sound so very Evil that I thot I should say something.
  1103. |> 
  1104. |> Hey, "evil" is most certainly an exaggeration. ;-)  I agree that working
  1105. |> directories aren't going away soon, if ever, but I maintain that they should
  1106. |> never be used by code that wasn't written by Apple Blue Meanies.  One major
  1107. |> disadvantage is that there is a fixed maximum number of working directories
  1108. |> for all applications on the machine, and thought I'm sure the system tries
  1109. |> to be clever at deallocating them as soon as they are no longer needed, one
  1110. |> could run out if one opens many files from different folders.
  1111.  
  1112. I expect that is true, but under system 7 I have been able to allocate
  1113. 84384 of them, all with different PBProcIDs. (that number is vague in my memory,
  1114. but it is 5 digits long and starts with an 8. Im sure of that). If thats not
  1115. enough, I stopped it htere, I didn't let it go on until it ran out (Im too lazy);
  1116. and as far as I know the system had no way of knowing that I was not going to
  1117. use 'em. How could the system know that I had no more plans to use a
  1118. particular WD that I allocated myself (or even one that it gave me?)
  1119.  
  1120. Of course, System 6, 5, 4, etc may not be so nice but then I'm not advocating
  1121. allocating yer own WDs for them. I see no reason to bother, SFGetFile always
  1122. give you one (and I very much expect it does not give you duplicates, although
  1123. I am not sure, so that overloading things that way would take a lot of double-
  1124. clicking)
  1125.  
  1126. !> Another problem
  1127. |> is that as long as a working directory exists for a folder, when you try to
  1128. |> throw away that folder, the Finder will complain that the item is "in use" or
  1129. |> contains items that are "in use".  I'm sure this is very confusing for
  1130. |> novices, and is the main reason I don't use working directories.
  1131. |> 
  1132.  
  1133. I did not know ->that<-. But it is very easy to fix. It requries very
  1134. little care, because there is only one routine in my program anyway that can
  1135. destroy a document, so I'll use that to check for any other documents that use
  1136. the same WD and if none are found I'll close it. That doesn't sound hard.
  1137.  
  1138. But if there are any other little traps waiting to screw me up like that, I'd
  1139. appreciate if you would bring them up. A few more little (but nasty) things
  1140. like that last one, and I'll have to admit their problem outweigh their
  1141. advantages.
  1142.  
  1143.  
  1144.  
  1145. - -------------------------
  1146.  
  1147. From: johnsd2@rs6225.ecs.rpi.edu (Daniel Norman Johnson)
  1148. Subject:  about working directories (was Re: StandardPutFile)
  1149. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  1150. Date: Tue, 11 Feb 1992 21:12:07 GMT
  1151.  
  1152. In article <20177@goofy.Apple.COM>, ABSURD@applelink.apple.com (Tim Dierks, ToyMeister, Cray abuser) writes:
  1153. |> In article <_=ds!d-@rpi.edu>, johnsd2@vccsouth20.its.rpi.edu (Daniel Norman Johnson) writes:
  1154. |> > 
  1155. |> > In article <1992Feb8.200712.10768@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  1156. |> > |> In article <zacs-vl@rpi.edu> johnsd2@rpi.edu writes:
  1157. |> > |> >The vRefNum you get from StandardPutFile and StandardGetFile is *REALLY*
  1158. |> > |> >a volume reference number, *NOT* a working directory reference number.
  1159. |> > 
  1160. |> >     [ and so on until... ]
  1161. |> > 
  1162. |> > |> NoNoNoNo.  Working directories are a compatibility hack for applications
  1163. |> > |> that don't know about HFS and directory IDs.  You never have to make your
  1164. |> > |> own.  When using the old Standard File routines, simply pass the contents
  1165. |> > |> of the vRefNum field in the reply record to _GetWDInfo.  This routine will
  1166. |> > |> return the corresponding _real_ volume refNum and a directoryID.  Once you
  1167. |> > |> have these, you need not consider the wdRefNum any longer.  If you are using
  1168. |> > |> the new Standard File routines, just use the fileSpec, or its component parts.
  1169. |> > 
  1170. |> >     [ and there's more, but this is what I wanted to comment on ]
  1171. |> > 
  1172. |> > I assure you, this particular hack is not going anywhere. If apple removes
  1173. |> > it, every application that uses SFGetFile will break. It does mean
  1174. |> > using 1 less variable, however, and I don't see any reason why the system
  1175. |> > can't keep track of something for me.
  1176. |> 
  1177. |> In this case, there's a couple of good reasons not to have the System keeping
  1178. |> track of this for you.  First, the system doesn't have any way to tell what 
  1179. |> directory records you're using and which you're not.  If I open and close
  1180. |> 500 files in your application, should the system maintain 500 different
  1181. |> working directories for the locations of each of these files?  How can it
  1182. |> be sure that your program will never need to look at any of these files
  1183. |> again?  Obviously, it's going to need to deallocate some of the records at
  1184. |> some point.  If you go back and try to use that working directory again,
  1185. |> Bad Things will happen.
  1186.  
  1187. (boy, if we keep this up, we'll get ourselves a genuine flame war!) :)
  1188. I don't think you are going to do that, but if you do in *my* app, you're
  1189. covered because the working directory for each doc is stored in its record
  1190. (along with various thigns like a handle to the document data); this record
  1191. hangs off a handle in the refCon of the window record. So, when I close (for
  1192. any reason) a document, its easy to tell if I should close the WD. I'm am going
  1193. to do this (haven't yet) because of the revelation I got from JohnC that the
  1194. system will not let anyone destroy dirs that have WDs to them.
  1195.  
  1196. That is a real concern to me (I hope there are no more like it) but you must
  1197. realize that to allocate 500 WDs you must open 500 files in different
  1198. directories. If you want to do this simultaneously, you must have memory for them
  1199. all. Do you think this will happen? More relevantly, will it be usefull? I can
  1200. say the answer is no for any app that I have ever written, but if it is
  1201. yes for yours, by all means use some other technology for your app.
  1202.  
  1203. !>  Secondly, you're abstracting yourself from the
  1204. |> actual structure of the file system and from the approved format for these
  1205. |> values.  This means that if you need to index into a sub-directory, you'll
  1206. |> actually have to create a working directory to get the single, 16-bit
  1207. |> number the rest of your code expects.  Furthermore, if you want to use
  1208. |> alias records, etc, you'll have to resolve the working directory to build
  1209. |> the FSSpec you need.  It seems like a lot of useless work to convert back
  1210. |> and forth, back and forth.  Why not just use an FSSpec?  It's also just
  1211. |> one variable, only it's a little bigger than a vRefNum + filename (which is
  1212. |> 2 variables!)
  1213. |> 
  1214. |> Support for working directories may not be forever.  It's hard to say at
  1215. |> this point, but you should avoid using working directories if at all
  1216. |> possible.
  1217.  
  1218. This all started when I suggested using WD to decode File-Specs under
  1219. system-7 (yes, I know that has risks of its own, but this discussion has
  1220. so for proceeded assuming that that is what we want to do), so that you can
  1221. use StandardPutFile like SFPutFile. If your app creats a -folder- when
  1222. you do a SFPutFile, I think maybe you need to think about your design a bit.
  1223. StandardPutFile takes care of aliases for you, before it returns.
  1224. Of course, I would much prefer to use FSSpecs. I will, if I ever write something
  1225. system-7 dependant. However it is just additional complication before then.
  1226.  
  1227. How can working directories be removed without toasting every app that uses
  1228. SFGetFile and SFPutFile? I really don't see how this can be done (or why
  1229. it would) I suppose Apple could make it so OpenWD/PBOpenWD/etc is not
  1230. available to anything but the system. I think Apple would be very silly to do
  1231. this. It also seems odd that apple should add a new high-level equivalent to
  1232. the OS for this (OpenWD may be glued, but it is not in the OS until Sys-7.0,
  1233. according to IM-VI), and then remove the whole routine although maybe thats
  1234. just beaurocrasy for ya.
  1235.  
  1236. I wouldn't use WD for everything. They have shortcomings, and they have more
  1237. surprises then I thot they would. But they simplify things a bit, in some
  1238. cases. They seem easy enough to deal with to me, but that is partly because
  1239. of the way my applications are put together inside. So maybe something else
  1240. would work better for you. And there's no law that says you have to use
  1241. only one technique per app, unless I am very much mistaken. (tho it makes
  1242. things simpler)
  1243.  
  1244. It seems to me that this discussion is being to wind back on itself, and
  1245. cover things that we have already covered. I wonder if that is worth the
  1246. bandwidth. I certainly do NOT want to wind up having to defend the position
  1247. that WDs are the end-all and be-all of the MacOS file system.
  1248. I was just offering a solution for --->one<--- (count em) problem, not trying
  1249. to dictate how all file access is to be done. My solution does in fact solve
  1250. the problem, and it did before I presented it. (it will work better now that
  1251. I am better informed about some of the problems with WDs, tho)
  1252.  
  1253. There are lots of reasons you might not want to do it that way. The best I know
  1254. of is that it may not be convinient for you. But please don't complain
  1255. that the solution I proposed isn't adequate for solving some other, completely
  1256. disconnected problem. That's silly. unless of course *my* posts were implying
  1257. that WDs were For All Things. If so (I hope its not), I apologize. Honestly,
  1258. this is not the point I wished to get across, and I do not believe it myself.
  1259.  
  1260. But let me just make it clear what the problem was, and what I proposed.
  1261. The problem was that if you try to use the .sfFile.vRefNum field that
  1262. is returned in the reply to a StandardPutFile, it doesn't work (and is itself
  1263. -1, in this case tho that did not turn out to matter); I proposed that the
  1264. victim of this problem could use OpenWD to convert the .vRefNum and .parID
  1265. fields into a working directory and use that. I did mention the file-spec
  1266. routines, but they are not appropriate because they are system-7 only,
  1267. or I understand they are. (If they are not, somebody tell me, because I would
  1268. really rather use File-Specs. If its a matter of Glue, I use ThinkC 5.0 but
  1269. I have not seen any reference to them in the docs!)
  1270.  
  1271. I (oops) forgot about the H... routines. :( They would work, I just forgot.
  1272. I have already apologized, and I don't think it is all THAT bad, as after
  1273. all several (ok 2) people have since mentioned them.
  1274.  
  1275. Now don't be put off, I just don't want to defend a position I dont buy
  1276. into myself! I do still want to hear about the wierd and wonderfull nature
  1277. of Working Directories (particularly pitfalls, as I have already picked up
  1278. one valuable item that I did not know) and particularly, if Apple has plans
  1279. to change the FSSpec record (I have a feeling Murphy is going to Get Me that
  1280. way, And Ill have to use FSp* anyway.)
  1281.  
  1282. I just want to make it clear what I was saying. I looks (to me) like I must
  1283. not have been clear enough about it, and wound up arguing something I didn't
  1284. mean.
  1285.  
  1286.  
  1287.  
  1288. - -------------------------
  1289.  
  1290. From: jcav@quads.uchicago.edu (JohnC)
  1291. Subject:  about working directories (was Re: StandardPutFile)
  1292. Organization: The Royal Society for Putting Things on Top of Other Things
  1293. Date: Tue, 11 Feb 1992 20:40:02 GMT
  1294.  
  1295. In article <_5gsr0n@rpi.edu> johnsd2@rpi.edu writes:
  1296. >So I can keep track of 3 fields instead of 2. Hmmmmm... Of course under system
  1297. >7 the system will take care of it for me, and I will (honest honest) use them
  1298. >when I write Sys-7 dependant stuff. But I get to write the FSp routines if
  1299. >it doesn't. Sounds like I get to keep track of 'em.
  1300.  
  1301. <sigh>  Here is are two code fragments:
  1302.  
  1303. {method A}
  1304. VAR    theName:Str255;
  1305.     theVolume:integer;
  1306.     theRefnum:integer;
  1307.     err:OSErr;
  1308.  
  1309.     err:=FSOpen(theName,theVolume,theRefnum); 
  1310.  
  1311. {method B}
  1312. VAR    theSpec:FSSpec;
  1313.     theRefnum:integer;
  1314.     err:OSErr;
  1315.  
  1316.     err:=HOpen(theSpec.vRefNum,theSpec.dirID,theSpec.name,
  1317.                fsRdWrPerm,theRefnum); 
  1318.  
  1319. Method A relies on working directories.  Method B does not, using the
  1320. fileSpec record in a way that is _not_ dependent upon System 7.  There are
  1321. no "FSp routines" to be written.
  1322.  
  1323. -- 
  1324. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  1325. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  1326. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  1327. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  1328.  
  1329.  
  1330.  
  1331. - -------------------------
  1332.  
  1333. From: jcav@quads.uchicago.edu (JohnC)
  1334. Subject:  about working directories (was Re: StandardPutFile)
  1335. Date: 11 Feb 92 21:54:53 GMT
  1336. Organization: The Royal Society for Putting Things on Top of Other Things
  1337.  
  1338. In article <g7gs+xq@rpi.edu> johnsd2@rpi.edu writes:
  1339. >But let me just make it clear what the problem was, and what I proposed.
  1340. >The problem was that if you try to use the .sfFile.vRefNum field that
  1341. >is returned in the reply to a StandardPutFile, it doesn't work (and is itself
  1342. >-1, in this case tho that did not turn out to matter); I proposed that the
  1343. >victim of this problem could use OpenWD to convert the .vRefNum and .parID
  1344. >fields into a working directory and use that. I did mention the file-spec
  1345. >routines, but they are not appropriate because they are system-7 only,
  1346. >or I understand they are. (If they are not, somebody tell me, because I would
  1347. >really rather use File-Specs. If its a matter of Glue, I use ThinkC 5.0 but
  1348. >I have not seen any reference to them in the docs!)
  1349. >
  1350. >I (oops) forgot about the H... routines. :( They would work, I just forgot.
  1351. >I have already apologized, and I don't think it is all THAT bad, as after
  1352. >all several (ok 2) people have since mentioned them.
  1353.  
  1354. The problem is how to use FileSpecs without requiring the System 7 high-level
  1355. file manager calls.  The solution is the "H-routines" that you forgot about.
  1356. It is _not_ necessary to open working directories.
  1357.  
  1358. -- 
  1359. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  1360. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  1361. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  1362. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  1363.  
  1364.  
  1365.  
  1366. - -------------------------
  1367.  
  1368. From: johnsd2@rs6221.ecs.rpi.edu (Daniel Norman Johnson)
  1369. Subject:  about working directories (was Re: StandardPutFile)
  1370. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  1371. Date: Wed, 12 Feb 1992 20:38:54 GMT
  1372.  
  1373. In article <1992Feb11.215453.22685@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  1374. |> 
  1375. |> The problem is how to use FileSpecs without requiring the System 7 high-level
  1376. |> file manager calls.  The solution is the "H-routines" that you forgot about.
  1377. |> It is _not_ necessary to open working directories.
  1378. |> 
  1379.  
  1380. Is it? Well, if you like. This discussion certainly applies to that in any
  1381. case. I was not thinking in terms of a general case particularly when
  1382. I suggested Working Directories.
  1383.  
  1384. H... routines are a solution. If you are saying the WD are not a solution,
  1385. well, if you say so. I find that difficult to buy. (if you had not noticed);
  1386.  
  1387. But to each his own.
  1388.  
  1389. By the way, I believe you asked at some point (I've lost track!) what was
  1390. going on with my test. I had assumed that ProcIDs were not being ignored. So
  1391. what I was really doing was allocating the same WD 8 zillion times. Not very
  1392. usefull, is it? At any rate 40 WDs will certainly do fine. (for me that is,
  1393. if its not good enough for you, don't use them)
  1394.  
  1395.  
  1396.  
  1397. - -------------------------
  1398.  
  1399. From: johnsd2@rs6225.ecs.rpi.edu (Daniel Norman Johnson)
  1400. Subject:  StandardPutFile
  1401. Organization: Information Technology Services, Rennselaer Polytechnic Institute.
  1402. Date: Tue, 11 Feb 1992 19:56:05 GMT
  1403.  
  1404. In article <1992Feb9.184946.2951@midway.uchicago.edu>, jcav@quads.uchicago.edu (JohnC) writes:
  1405. |> In article <6xds##d@rpi.edu> johnsd2@rpi.edu writes:
  1406. |> >What --->is<--- is bug is what happens if you follow my instructions however.
  1407. |> >I said that OpenWD() should be called with a PBProcID field of 0, and this
  1408. |> >is WRONG. I thot PBProcID was for your applications use, but it isn't. Its
  1409. |> >the way the system knows who owns any particular Working Directory. Pass
  1410. |> >your applications signature.
  1411. |> >
  1412. |> >Passing 0 works, but it means that you would be SHARING Working directories
  1413. |> >with any other app that also passes 0, which is bad. But then, that's
  1414. |> >what you get for listening to me. :)
  1415. |> 
  1416. |> Actually, under Multifinder/Process Manager, the procID is ignored by the
  1417. |> system.  Instead, it tags the working directory with a value uniquely
  1418. |> identifying the process that created it, to facilitate automatic
  1419. |> deallocation when the process terminates.
  1420. |> 
  1421.  
  1422. Really? Hmmmm. Where are you finding this stuff out? I do not remember IM-VI
  1423. saying anything about it (tho I could easily have missed it), but Im glad to know
  1424. the system is going to be mercifull. But it seems odd to me that IM-IV should
  1425. say that you must use your Applications Signature. What does this do, if
  1426. anything?
  1427.  
  1428. Also, Under Multifinder/Sys-7, does PBGetWDInfo index through -all- of the
  1429. Working Directories, or just yours?
  1430.  
  1431. <groan>, the worst part is that if the system just -ignores- the ProcID then
  1432. my tests (which assumed you can allocate lots and lots of WDs if you gave
  1433. them different proc-ids) are garbage. I'll have to write a new one, that
  1434. allocates different folders. bleah. All that wasted work (about 10 lines..) :<
  1435.  
  1436.  
  1437.  
  1438.  
  1439. - -------------------------
  1440.  
  1441. From: jcav@quads.uchicago.edu (JohnC)
  1442. Subject:  StandardPutFile
  1443. Organization: The Royal Society for Putting Things on Top of Other Things
  1444. Date: Tue, 11 Feb 1992 20:19:36 GMT
  1445.  
  1446. In article <g5gs4=p@rpi.edu> johnsd2@rpi.edu writes:
  1447. >|> Actually, under Multifinder/Process Manager, the procID is ignored by the
  1448. >|> system.  Instead, it tags the working directory with a value uniquely
  1449. >|> identifying the process that created it, to facilitate automatic
  1450. >|> deallocation when the process terminates.
  1451. >|> 
  1452. >
  1453. >Really? Hmmmm. Where are you finding this stuff out? I do not remember IM-VI
  1454. >saying anything about it (tho I could easily have missed it), but Im glad to
  1455. >know the system is going to be mercifull. But it seems odd to me that IM-IV
  1456. >should say that you must use your Applications Signature. What does this do,
  1457. >if anything?
  1458.  
  1459. The stuff about Multifinder's handling of the procID was in one of the tech
  1460. notes about Multifinder, I believe.  Either that or the Programmer's Guide
  1461. to Multifinder.  The reason that IM-6 doesn't talk about it is that both
  1462. Multifinder and working directories are _obsolete_.  The discrepancy
  1463. between IM-4 and IM-6 that you mention is a symptom of a big problem with
  1464. Inside Macintosh, which is that certain parts of older volumes become
  1465. inaccurate as the Mac evolves, but there's no easy way to tell, except by
  1466. memorizing all six volumes.  (which I have done, ;-)
  1467.  
  1468. >Also, Under Multifinder/Sys-7, does PBGetWDInfo index through -all- of the
  1469. >Working Directories, or just yours?
  1470.  
  1471. I have no idea.
  1472.  
  1473. ><groan>, the worst part is that if the system just -ignores- the ProcID then
  1474. >my tests (which assumed you can allocate lots and lots of WDs if you gave
  1475. >them different proc-ids) are garbage. I'll have to write a new one, that
  1476. >allocates different folders. bleah. All that wasted work (about 10 lines..) :<
  1477.  
  1478. There has always been a fixed limit of 40 working directories.  I'm nearly
  1479. certain that this limit still exists in System 7.  Could someone from Apple
  1480. comment?
  1481.  
  1482. -- 
  1483. John Cavallino                  |  EMail: jcav@midway.uchicago.edu
  1484. University of Chicago Hospitals |         John_Cavallino@uchfm.bsd.uchicago.edu
  1485. Office of Facilities Management | USMail: 5841 S. Maryland Ave, MC 0953
  1486. B0 f++ c+ g+ k s+(+) e+ h- pv   |         Chicago, IL  60637
  1487.  
  1488.  
  1489.  
  1490. - -------------------------
  1491.  
  1492. From: keith@Apple.COM (Keith Rollin)
  1493. Subject:  about working directories (was Re: StandardPutFile)
  1494. Date: 14 Feb 92 02:34:26 GMT
  1495. Organization: Apple Computer Inc., Cupertino, CA
  1496.  
  1497. In article <NEERI.92Feb11105324@iis.ethz.ch> neeri@iis.ethz.ch (Matthias Ulrich Neeracher) writes:
  1498. >
  1499. >The reason why I use working directories in some of my applications is that I
  1500. >need ways to set the default directory, and HSetVol will break at the moment
  1501. >someone else decides to call GetVol/SetVol. So, I see no alternative to using
  1502. >working directories.
  1503.  
  1504. I would argue with first, your premise, and second, your solution.
  1505.  
  1506. My initial feeling is that your applications do not need to set the
  1507. default directory. I've been programming the Mac for many years, and
  1508. have never needed to set the default directory. Many people think they
  1509. do, but it turns out that many times they are wrong. For instance,
  1510. many people look at the description for OpenResFile and feel that they
  1511. need to set the default directory, not realizing that there is an
  1512. HOpenResFile call. Others feel that they need to set the default
  1513. directory when porting a UNIX application to the Mac. This is probably
  1514. the most valid reason I've heard for setting the default directory, but
  1515. my position is still that the port should do things the Mac way and use
  1516. the native file system calls.
  1517.  
  1518. Just because _I've_ never needed to set the default directory doesn't
  1519. mean that you haven't. If you still feel that you need to set the
  1520. default directory, then I'd probably take an approach that didn't
  1521. require me to create a working directory ID. For instance, calling
  1522. HSetVol is perfectly OK, so long as you match it with calls to HGetVol
  1523. in your own code, and make sure that things like DA's running in your
  1524. application space (a rarity these days) aren't tripped up by it. If
  1525. this matters to you, simply make sure that you leave the default volume
  1526. set to something represented by a working directory just before calling
  1527. WaitNextEvent, and then restore it to what you want afterwards.
  1528.  
  1529. Remember, SetVol was brought to you by the same people who brought you
  1530. SetPt. It was merely a means to save a few bytes in applications that
  1531. had only 50K or so of heap to run around in. These savings mean very
  1532. little in these days of megabyte machines, so it's better to completely
  1533. use the "clean" solution of FSpXXX and HXXX calls.
  1534.  
  1535. -- 
  1536. - ----------------------------------------------------------------------------
  1537. Keith Rollin           ---            <Taligent .signature under construction>
  1538. Disclaimer: Pretty soon, I really _won't_ be speaking for Apple...
  1539.  
  1540.  
  1541.  
  1542. - -------------------------
  1543.  
  1544. From: neeri@iis.ethz.ch (Matthias Ulrich Neeracher)
  1545. Subject:  about working directories (was Re: StandardPutFile)
  1546. Date: 14 Feb 92 09:42:01 GMT
  1547. Organization: Integrated Systems Laboratory, ETH, Zurich
  1548.  
  1549. In article <62780@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes:
  1550. >In article <NEERI.92Feb11105324@iis.ethz.ch> neeri@iis.ethz.ch (Matthias Ulrich Neeracher) writes:
  1551. >>
  1552. >>The reason why I use working directories in some of my applications is that I
  1553. >>need ways to set the default directory, and HSetVol will break at the moment
  1554. >>someone else decides to call GetVol/SetVol. So, I see no alternative to using
  1555. >>working directories.
  1556. >
  1557. >I would argue with first, your premise, and second, your solution.
  1558. >
  1559. >My initial feeling is that your applications do not need to set the
  1560. >default directory. I've been programming the Mac for many years, and
  1561. >have never needed to set the default directory.
  1562.  
  1563. OK, I agree, a normal application does not need to do this, but...
  1564.  
  1565. >Others feel that they need to set the default
  1566. >directory when porting a UNIX application to the Mac. This is probably
  1567. >the most valid reason I've heard for setting the default directory, but
  1568. >my position is still that the port should do things the Mac way and use
  1569. >the native file system calls.
  1570.  
  1571. This was exactly my problem. I was porting Perl to the Mac, and if some script
  1572. wants to call chdir(), I can't well refuse.
  1573.  
  1574. >If you still feel that you need to set the
  1575. >default directory, then I'd probably take an approach that didn't
  1576. >require me to create a working directory ID. For instance, calling
  1577. >HSetVol is perfectly OK, so long as you match it with calls to HGetVol
  1578. >in your own code, and make sure that things like DA's running in your
  1579. >application space (a rarity these days) aren't tripped up by it. If
  1580. >this matters to you, simply make sure that you leave the default volume
  1581. >set to something represented by a working directory just before calling
  1582. >WaitNextEvent, and then restore it to what you want afterwards.
  1583.  
  1584. I thought of doing something like this, but unfortunately, there is no list of
  1585. _Traps that might mess up your HSetVol_. WaitNextEvent is certainly one of
  1586. them, so is AESend if I wait for a reply. What about SFPutFile ? PrOpen ? Can I
  1587. rely on all Apple written code preserving my HSetVol, and not merely my SetVol ?
  1588.  
  1589. The other solution would be to bracket all calls to the standard C io library
  1590. with HSetVols. Not that attractive a prospect.
  1591.  
  1592. Matthias
  1593.  
  1594. - ---
  1595. Matthias Neeracher                                      neeri@iis.ethz.ch
  1596.   "Nur die halbe Welt ist Teflon und Asbest" -- Einstuerzende Neubauten 
  1597.  
  1598.  
  1599.  
  1600. - -------------------------
  1601.  
  1602. From: d88-jwa@hemul.nada.kth.se (Jon W{tte)
  1603. Subject:  about working directories (was Re: StandardPutFile)
  1604. Date: 14 Feb 92 17:43:18 GMT
  1605. Organization: Royal Institute of Technology, Stockholm, Sweden
  1606.  
  1607. .ch> neeri@iis.ethz.ch (Matthias Ulrich Neeracher) writes:
  1608.  
  1609.    >Others feel that they need to set the default
  1610.    >directory when porting a UNIX application to the Mac. This is probably
  1611.    >the most valid reason I've heard for setting the default directory, but
  1612.    >my position is still that the port should do things the Mac way and use
  1613.    >the native file system calls.
  1614.  
  1615.    This was exactly my problem. I was porting Perl to the Mac, and if some
  1616.    script wants to call chdir(), I can't well refuse.
  1617.  
  1618. I've found that an easier approach is to write your _own_ stdio library,
  1619. as well as underlying unixio library. Your own library can have variables
  1620. for which directory is considered the "default" and push that vRefNum/dirID
  1621. pair into the calls it makes. Thus you do not have to use SetVol at all,
  1622. since your own library does the only proper thing and uses the HFileCall
  1623. calls.
  1624.  
  1625.    rely on all Apple written code preserving my HSetVol, and not merely my
  1626.    SetVol ?
  1627.  
  1628. HSetVol is dangerous. Don't use it. And when you do, set it back right
  1629. afterwards.
  1630.  
  1631. You could probably hack the Think libraries to support that feature,
  1632. since you have the sources. Just don't distribute the modified source !
  1633.  
  1634. --
  1635. This Signature is distributed under the conditions of the Signature License,
  1636. available at a fee from   h+@nada.kth.se  (Jon W{tte)  Reading the Signature
  1637. implies that you accept to be bound by the terms in said License. Should you
  1638. not agree on any of these terms, you must return the Signature unread to me.
  1639.  
  1640.  
  1641.  
  1642. ---------------------------
  1643.  
  1644. End of C.S.M.P. Digest
  1645. **********************
  1646.